<template>
	<view>
		<nav-bars title="企业实名认证"></nav-bars>
		<view class="information">
			<view class="information_tit">请提交企业认证资料</view>
			<view class="information_from">
				<view class="information_lable">企业名称</view>
				<input type="text" v-model="EnterpriseName" placeholder-style="color:#B6B6B6;" placeholder="请输入企业名称" />
			</view>
			<view class="information_from">
				<view class="information_lable">法人姓名</view>
				<input type="text" v-model="legalName" placeholder-style="color:#B6B6B6;" placeholder="请输入法人姓名" />
			</view>
			<view class="information_from">
				<view class="information_lable">法人证件号</view>
				<input type="text" v-model="IdCard" placeholder-style="color:#B6B6B6;" placeholder="请输入法人证件号" />
			</view>
			<view class="information_from">
				<view class="information_lable">认证类型</view>
				<view @click="show = true" :style="{ color: type == '' ? '#B6B6B6' : '#333' }">{{ type == '' ? '请选择认证类型' : type }}</view>
			</view>
			<view class="information_time">
				<view class="information_timeTit">法人手机号码</view>
				<input type="number" :value="Phone" @input="bindKeyInput" placeholder-style="color:#B6B6B6;" placeholder="请输入法人手机号码" />
			</view>
			<view class="information_time">
				<view class="information_timeTit">企业对公账户</view>
				<input type="text" v-model="account" placeholder-style="color:#B6B6B6;" placeholder="请输入企业对公账户" />
			</view>
			<view class="information_time">
				<view class="information_timeTit">支付行号</view>
				<input type="text" v-model="BankNum" disabled @click="BankNumClick" placeholder-style="color:#B6B6B6;" placeholder="请选择支付行号(12位数字)" />
			</view>
			<view class="information_time">
				<view class="information_timeTit">开户银行名称</view>
				<input type="text" v-model="bankName" placeholder-style="color:#B6B6B6;" placeholder="请输入开户银行名称" />
			</view>
			<view class="information_time">
				<view class="information_timeTit">开户行支行名称</view>
				<input type="text" v-model="OpenBankName" placeholder-style="color:#B6B6B6;" placeholder="请输入开户行支行名称" />
			</view>

			<view class="information_time" v-if="authType == 2">
				<view class="information_timeTit">统一社会信用代码</view>
				<input type="text" v-model="uniCredit" placeholder-style="color:#B6B6B6;" placeholder="请输入统一社会信用代码" />
			</view>

			<view class="information_time" v-if="authType == 1">
				<view class="information_timeTit">纳税识别号</view>
				<input type="text" v-model="taxRegister" placeholder-style="color:#B6B6B6;" placeholder="请输入纳税识别号" />
			</view>
			<view class="information_time" v-if="authType == 1">
				<view class="information_timeTit">营业执照号</view>
				<input type="text" v-model="businessLicense" placeholder-style="color:#B6B6B6;" placeholder="请输入营业执照号" />
			</view>
			<view class="information_time" v-if="authType == 1">
				<view class="information_timeTit">组织机构代码</view>
				<input type="text" v-model="organizationCode" placeholder-style="color:#B6B6B6;" placeholder="请输入组织机构代码" />
			</view>

			<view class="information_btn">
				<!-- @click="UpMessage" -->
				<!-- <view v-if="authType == 1" class="btn">提交资料1</view> -->
				<view class="btn" @click="UpMessage">提交资料</view>
			</view>
			<view class="information_Tips">
				<checkbox-group @change="checkboxChange" class="checkbox"><checkbox v-mode="checked" :checked="checked" /></checkbox-group>
				<view class="information_TipsList" @click="checkedChange">
					<view style="color: #B0B0B0;">我已阅读并同意</view>
					<view style="color: #C3AB7C;" @click.stop="agent">《用户授权协议》</view>
					<!-- <view style="color: #C3AB7C;">《融易装App用户隐私协议》</view> -->
				</view>
			</view>
		</view>
	</view>
</template>
<script>
var Rexphone = /^1[2|3|4|5|6|7|8|9]\d{9}$/;
import Https from '@/service/verification.js';
export default {
	name: '',
	components: {},
	data() {
		return {
			authType: null, //认证类型 1:三证 2:一证
			EnterpriseName: '', //企业名称
			legalName: '', //法人姓名
			type: '身份证', //法人证件类型((1身份证,2护照,3军官证,4回乡证,5台胞证,6警官证,7士兵证,99其它证件))
			typeId: '1', //法人证件类型id
			IdCard: '', //法人证件号
			Phone: '', //法人手机号码
			account: '', //企业对公账户
			bankName: '', //开户银行名称
			OpenBankName: '', //开户行支行名称
			BankNum: '', //支付行号
			uniCredit: '', //统一社会信用代码

			taxRegister: '', //税务号
			businessLicense: '', //营业执照号
			organizationCode: '', //组织机构代码
			checked: false, //协议多选框
			zhiHangInfo: '',
			EnterpriseImageList: '',
			EnterpriseThreeImageList: ''
		};
	},
	onReady() {
		var that = this;
		var Enterprise = uni.getStorageSync('Enterprise');
		var EnterpriseThree = uni.getStorageSync('EnterpriseThree');
		// console.log(Enterprise);
		// 企业认证一证
		if (Enterprise) {
			// console.log(Enterprise, 'Enterprise');
			uni.removeStorageSync('EnterpriseThree');
			that.EnterpriseName = Enterprise.businessMes.Name;
			that.legalName = Enterprise.BankCard.Name;
			that.IdCard = Enterprise.BankCard.IdNum;
			that.uniCredit = Enterprise.businessMes.RegNum;
			that.EnterpriseImageList = Enterprise.BankCard.imageList;
			that.authType = 2;
			return;
		}
		// 三证
		if (EnterpriseThree) {
			// console.log(EnterpriseThree, 'EnterpriseThree');
			uni.removeStorageSync('Enterprise');
			that.EnterpriseName = EnterpriseThree.businessMes.Name;
			that.legalName = EnterpriseThree.BankCard.Name;
			that.IdCard = EnterpriseThree.BankCard.IdNum;
			that.organizationCode = EnterpriseThree.organization.OrgCode;
			that.businessLicense = EnterpriseThree.businessMes.RegNum;
			that.EnterpriseThreeImageList = EnterpriseThree.BankCard.imageList;
			that.authType = 1;
			return;
		}
	},
	onUnload() {
		uni.removeStorageSync('Enterprise');
		uni.removeStorageSync('EnterpriseThree');
	},
	onLoad(options) {
		var that = this;
		// console.log(options);
		if (options.authType) {
			that.authType = options.authType;
		}
	},

	onShow() {
		// console.log();
		var that = this;
		if (that.zhiHangInfo != '') {
			// console.log(that.zhiHangInfo);
			that.bankName = that.zhiHangInfo.BankName;
			that.OpenBankName = that.zhiHangInfo.zhihang.BANK_NAME;
			that.BankNum = that.zhiHangInfo.zhihang.NET_BANK_CODE;
		}
	},
	mounted() {},
	methods: {
		agent(){
			uni.navigateTo({
				url: '/pages_login/pages/login/agreement/index',
			});
		},
		BankNumClick() {
			uni.navigateTo({
				url: '/pages_Verification/verification/keywordBank/BankCode/list'
			});
		},
		checkboxChange(e) {
			var that = this;
			that.checked = e.detail.value[0] == 'false' ? 'true' : e.detail.value[0] == undefined ? false : true;
			// console.log(that.checked);
		},
		GegBankName(e) {
			console.log(e);
			var that = this;
			var value = e.detail.value;
			let params = {
				card_no: value
			};
			if (value != '') {
				Https.GetBinName(params).then(res => {
					if (res.code == 1) {
						console.log(res.data);
						// var data = res.data.cardBinInfo;
						// that.bank_name = data.bankName; //卡名称
						// that.BinBackInfo = data;
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						});
					}
				});
			}
		},
		UpMessage() {
			var that = this;
			var authType = that.authType; //认证类型 1:三证 2:一证
			var EnterpriseName = that.EnterpriseName; //企业名称
			var legalName = that.legalName; //法人姓名
			var typeId = that.typeId; //法人证件类型id
			var IdCard = that.IdCard; //法人证件号
			var Phone = that.Phone; //法人手机号码
			var account = that.account; //企业对公账户
			var bankName = that.bankName; //开户银行名称
			var OpenBankName = that.OpenBankName; //开户行支行名称
			var BankNum = that.BankNum; //支付行号
			var uniCredit = that.uniCredit; //统一社会信用代码

			var taxRegister = that.taxRegister; //税务号
			var businessLicense = that.businessLicense; //营业执照号
			var organizationCode = that.organizationCode; //组织机构代码

			var checked = that.checked; //协议多选框

			// if ( taxRegister != '' && businessLicense != '' && organizationCode != '') {
			// console.log(authType, 'authType1');
			if (
				authType == 1 &&
				EnterpriseName != '' &&
				legalName != '' &&
				IdCard != '' &&
				Phone != '' &&
				Rexphone.test(Phone) &&
				account != '' &&
				bankName != '' &&
				OpenBankName != '' &&
				BankNum != '' &&
				taxRegister != '' &&
				businessLicense != '' &&
				organizationCode != '' &&
				checked == true
			) {
				let params = {
					authType: authType, //认证类型 1:三证 2:一证
					company_name: EnterpriseName, //企业名称
					legal_name: legalName, //法人姓名
					identity_type: typeId, //法人证件类型((1身份证,2护照,3军官证,4回乡证,5台胞证,6警官证,7士兵证,99其它证件))默认身份证
					legal_ids: IdCard, //法人证件号码
					legal_phone: Phone, //法人手机号
					account_no: account, //企业对公账户
					parent_bank_name: bankName, //开户银行名称
					bank_name: OpenBankName, //开户行支行名称
					uniCredit: uniCredit, //支付行号(12位数字)
					taxRegister: taxRegister, //税务登记证（三证） 认证类型为 1 时必传
					businessLicense: businessLicense, //营业执照号（三证） 认证类型为 1 时必传
					organizationCode: organizationCode, //组织机构代码（三证） 认证类型为 1 时必传
					union_bank: BankNum, //支付行号(12位数字)
					businessLicense_img_id: that.EnterpriseThreeImageList.imagebusiness.id, //营业执照图片ID (必传)
					organizationCode_img_id: that.EnterpriseThreeImageList.imageorganization.id, //组织机构代码图片ID（三证时必传）
					taxRegister_img_id: that.EnterpriseThreeImageList.imageTax.id, //税务登记证图片ID（三证时必传）
					bankAccCert_img_id: that.EnterpriseThreeImageList.imageaccount == null ? '' : that.EnterpriseThreeImageList.imageaccount.id, //银行开户证明图片ID（非必传）
					idCard_front_img_id: that.EnterpriseThreeImageList.imagejust.id, //法人身份证正面
					idCard_back_img_id: that.EnterpriseThreeImageList.imageback.id //法人身份证背面
				};
				uni.showLoading({
					title: '正在提交...'
				});
				Https.setCompanyInfo(params).then(res => {
					if (res.code == 1) {
						console.log(res.data);
						uni.hideLoading();
						var status = res.data.result;
						// 1:审核中 2：审核成功。 3：审核失败。
						// isPersonal: null, // false企业 ,true个人
						// status: null, // 0提交成功   1通过   2不通过
						if (status == 1) {
							uni.showToast({
								title: '提交成功',
								icon: 'success',
								duration: 2000
							});
							setTimeout(() => {
								uni.redirectTo({
									url: '/pages_Verification/verification/status/status?isPersonal=false&status=0'
								});
							}, 2100);
							return;
						}
						if (status == 2) {
							uni.showToast({
								title: '提交成功',
								icon: 'success',
								duration: 2000
							});
							setTimeout(() => {
								uni.redirectTo({
									url: '/pages_Verification/verification/status/status?isPersonal=false&status=1'
								});
							}, 2100);
							return;
						}
						if (status == 3) {
							uni.showToast({
								title: '提交成功',
								icon: 'success',
								duration: 2000
							});
							setTimeout(() => {
								uni.redirectTo({
									url: '/pages_Verification/verification/status/status?isPersonal=false&status=2'
								});
							}, 2100);
							return;
						}
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						});
					}
				});
				return;
			}
			if (
				authType == 2 &&
				EnterpriseName != '' &&
				legalName != '' &&
				IdCard != '' &&
				Phone != '' &&
				Rexphone.test(Phone) &&
				account != '' &&
				bankName != '' &&
				OpenBankName != '' &&
				BankNum != '' &&
				uniCredit != '' &&
				checked == true
			) {
				// console.log(2, 123);
				let params = {
					authType: authType, //认证类型 1:三证 2:一证
					company_name: EnterpriseName,
					legal_name: legalName,
					identity_type: typeId,
					legal_ids: IdCard,
					legal_phone: Phone,
					account_no: account,
					parent_bank_name: bankName,
					bank_name: OpenBankName,
					uniCredit: uniCredit,
					union_bank: BankNum,
					businessLicense_img_id: that.EnterpriseImageList.imagebusiness.id, //营业执照图片ID (必传)
					// organizationCode_img_id: params.organizationCode_img_id, //组织机构代码图片ID（三证时必传）
					// taxRegister_img_id: params.taxRegister_img_id, //税务登记证图片ID（三证时必传）
					bankAccCert_img_id: that.EnterpriseImageList.imageaccount == null ? '' : that.EnterpriseImageList.imageaccount.id, //银行开户证明图片ID（非必传）
					idCard_front_img_id: that.EnterpriseImageList.imagejust.id, //法人身份证正面
					idCard_back_img_id: that.EnterpriseImageList.imageback.id //法人身份证背面
				};
				uni.showLoading({
					title: '正在提交...'
				});
				Https.setCompanyInfo(params).then(res => {
					if (res.code == 1) {
						console.log(res.data);
						uni.hideLoading();
						var status = res.data.result;
						// 1:审核中 2：审核成功。 3：审核失败。
						// isPersonal: null, // false企业 ,true个人
						// status: null, // 0提交成功   1通过   2不通过
						if (status == 1) {
							uni.showToast({
								title: '提交成功',
								icon: 'success',
								duration: 2000
							});
							setTimeout(() => {
								uni.redirectTo({
									url: '/pages_Verification/verification/status/status?isPersonal=false&status=0'
								});
							}, 2100);
							return;
						}
						if (status == 2) {
							uni.showToast({
								title: '提交成功',
								icon: 'success',
								duration: 2000
							});
							setTimeout(() => {
								uni.redirectTo({
									url: '/pages_Verification/verification/status/status?isPersonal=false&status=1'
								});
							}, 2100);
							return;
						}
						if (status == 3) {
							uni.showToast({
								title: '提交成功',
								icon: 'success',
								duration: 2000
							});
							setTimeout(() => {
								uni.redirectTo({
									url: '/pages_Verification/verification/status/status?isPersonal=false&status=2'
								});
							}, 2100);
							return;
						}
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						});
					}
				});
				return;
			}
			// }

			if (uniCredit == '' && authType == 2) {
				uni.showToast({
					title: '请输入统一社会信用代码',
					icon: 'none',
					duration: 2000
				});
				return;
			}

			//认证类型 1:三证 2:一证
			if (that.authType == 1 && taxRegister == '') {
				uni.showToast({
					title: '请输入纳税识别号',
					icon: 'none',
					duration: 2000
				});
				return;
			}
			if (that.authType == 1 && businessLicense == '') {
				uni.showToast({
					title: '请输入营业执照号',
					icon: 'none',
					duration: 2000
				});
				return;
			}
			if (that.authType == 1 && organizationCode == '') {
				uni.showToast({
					title: '请输入组织机构代码',
					icon: 'none',
					duration: 2000
				});

				return;
			}

			if (EnterpriseName == '') {
				uni.showToast({
					title: '请输入企业名称',
					icon: 'none',
					duration: 2000
				});
				return;
			}
			if (legalName == '') {
				uni.showToast({
					title: '请输入法人姓名',
					icon: 'none',
					duration: 2000
				});
				return;
			}
			if (IdCard == '') {
				uni.showToast({
					title: '请输入法人证件号',
					icon: 'none',
					duration: 2000
				});
				return;
			}
			if (Phone == '') {
				uni.showToast({
					title: '请输入手机号码',
					icon: 'none',
					duration: 2000
				});
				return;
			}
			if (!Rexphone.test(Phone)) {
				uni.showToast({
					title: '手机号码有误！',
					icon: 'none',
					duration: 2000
				});
				return;
			}
			if (account == '') {
				uni.showToast({
					title: '请输入企业对公账户',
					icon: 'none',
					duration: 2000
				});
				return;
			}
			if (bankName == '') {
				uni.showToast({
					title: '请输入开户银行名称',
					icon: 'none',
					duration: 2000
				});
				return;
			}
			if (OpenBankName == '') {
				uni.showToast({
					title: '请输入开户行支行名称',
					icon: 'none',
					duration: 2000
				});
				return;
			}
			if (BankNum == '') {
				uni.showToast({
					title: '请上输入支付行号',
					icon: 'none',
					duration: 2000
				});
				return;
			}
			if (checked == false) {
				uni.showToast({
					title: '请勾选下方协议',
					icon: 'none',
					duration: 2000
				});
				return;
			}
			console.log(3);
		},
		// 验证只能输入数字
		validateNumber(val) {
			return val.replace(/\D/g, '');
		},
		// 手机号码的双向数据绑定只能输入数字
		bindKeyInput(e) {
			var that = this;
			let value = that.validateNumber(e.detail.value);
			that.Phone = value;
			return value;
		},
		// 协议多选框
		checkedChange() {
			this.checked = !this.checked;
		}
	}
};
</script>
<style lang="less">
page {
	background: #fff;
}
checkbox .wx-checkbox-input {
	border-radius: 0 !important; /* 圆角 */
	width: 26rpx; /* 背景的宽 */
	height: 26rpx; /* 背景的高 */
}
.information {
	padding: 32rpx;
	.information_tit {
		font-size: 60rpx;
		font-weight: 500;
		color: #212121;
		margin-bottom: 94rpx;
	}
	.information_from {
		display: flex;
		align-items: center;
		padding-bottom: 26rpx;
		border-bottom: 2rpx solid #f1f1f1;
		margin-bottom: 40rpx;
		.information_lable {
			width: 150rpx;
			font-size: 30rpx;
			font-weight: 500;
			color: #737373;
			margin-right: 32rpx;
		}
		input {
			font-size: 30rpx;
			font-weight: 500;
			color: #212121;
			flex: 1;
		}
	}
	.information_time {
		padding-bottom: 26rpx;
		border-bottom: 2rpx solid #f1f1f1;
		margin-bottom: 40rpx;
		.information_timeTit {
			font-size: 30rpx;
			font-weight: 500;
			color: #737373;
			margin-bottom: 24rpx;
		}
		.information_Mes {
			font-size: 30rpx;
			font-weight: 500;
			color: #212121;
		}
		input {
			font-size: 30rpx;
			font-weight: 500;
			color: #212121;
			flex: 1;
		}
	}
	.information_btn {
		padding-top: 29rpx;
		.btn {
			height: 90rpx;
			background: #c3ab7c;
			border-radius: 10rpx;
			font-size: 34rpx;
			font-weight: 500;
			color: #ffffff;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}
	.information_Tips {
		display: flex;
		align-items: flex-start;
		margin-top: 24rpx;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
		.information_TipsList {
			font-size: 26rpx;
			padding-top: 6rpx;
			font-weight: bold;
			display: flex;
			align-items: center;
			flex-wrap: wrap;
		}
	}
}
</style>
